<?php

namespace app\dao\office;

use app\dao\BaseDao;
use app\model\office\OfficeClass;
use think\db\Where;

class OfficeClassDao extends BaseDao
{

    public function getList(array $where)
    {
        return $this->getModel()->where('website_id', $where['website_id'])->field('title,garde,class_code,id')->paginate($where['pageSize']);
    }

    public function index(array $where)
    {
        return $this->search()
            ->with(['majors' => function ($query) {
                $query->withField(['id', 'title', 'level']);
            }])->withSearch(['title', 'major_id', 'garde', 'class_type', 'class_code'],
                ['class_code' => $where['class_code'], 'title' => $where['title'], 'major_id' => $where['major_id'],
                    'garde' => $where['garde'], 'class_type' => $where['class_type']])
            ->where('website_id', $where['website_id'])
            ->order('id', 'desc')->
            withoutField('update_time,delete_time,website_id')->order('major_id', 'asc')->paginate($where['pageSize']);
    }

    public function create(array $where)
    {
        return $this->getModel()->create($where);
    }

    public function updateDao(array $where)
    {
        return $this->getModel()->update($where);
    }

    public function deleteDao(array $where)
    {
        return $this->getModel()-> whereIn('id',$where['id']) -> update(['delete_time' => date('Y-m-d H:i:s', time())]);

    }

    protected function setModel(): string
    {
        return OfficeClass::class;
    }

    public function searchDao($where)
    {
        return $this->getModel()->withSearch(['title'], ['title' => $where['title']])->field('title,garde,class_code,id')->where('website_id', $where['website_id'])->paginate($where['pageSize']);
    }


    //------------------------------------------------------api--------------------------------------------------------------
    public function getClass(array $where){
        return $this->getModel()
            ->withoutField(['update_time','delete_time','create_time','class_code'])
            ->where('major_id',$where['major_id'])
            ->where('website_id', $where['website_id'])
//            ->where('garde',$where['garde'])
            ->select();
    }

}